//
//  HHYMainTabbarC.m
//  大股票
//
//  Created by apple on 2019/8/14.
//  Copyright © 2019 apple. All rights reserved.
//

#import "HHYMainTabbarC.h"
#import "HHYHeader.h"
//VC
#import "HHYHangQingVC.h"
#import "HHYZiXuanVC.h"
#import "HHYNaviVC.h"
#import "HHYStockCalculateVC.h"
#import "GPIndexViewController.h"
#import "GPBaseNavigationController_NN.h"
#import "FTQMineController.h"
#import "FTQLoginController.h"


@interface HHYMainTabbarC ()

@end

@implementation HHYMainTabbarC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.tabBar.backgroundImage = [UIImage xl_imageWithColor:UIColor.whiteColor size:CGSizeMake(hhy_kScreenWidth, hhy_kTabbarHeight)];
    
    [self addChildVC];
    
    
}

- (void)addChildVC {
    //首页
    GPIndexViewController *vc1 = [GPIndexViewController new];
    
    [self setupChildViewController:vc1 title:@"广场" imageName:@"广场-未选中" selectedImageName:@"广场-已选中"];
    //行情
    HHYHangQingVC *vc2 = [HHYHangQingVC new];
    [self setupChildViewController:vc2 title:@"行情" imageName:@"行情-未选中" selectedImageName:@"行情-已选中"];
    
    //盈亏计算
    HHYStockCalculateVC *vc3 = [HHYStockCalculateVC new];
    [self setupChildViewController:vc3 title:@"盈亏计算" imageName:@"盈亏计算-未选中" selectedImageName:@"盈亏计算-已选中"];
    
    //自选
    HHYZiXuanVC *vc4 = [HHYZiXuanVC new];
    [self setupChildViewController:vc4 title:@"自选" imageName:@"自选-未选中" selectedImageName:@"自选-已选中"];
    
    //个人中心
    FTQMineController *vc5 = [FTQMineController new];
    [self setupChildViewController:vc5 title:@"个人中心" imageName:@"个人中心-未选中" selectedImageName:@"个人中心-已选中"];
    
}

- (void)setupChildViewController:(UIViewController *)childVc title:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName
{

    // 1.设置控制器的属性
    childVc.tabBarItem.title = title;
    childVc.view.backgroundColor = UIColor.whiteColor;
    // 设置图标
    childVc.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    // 设置选中的图标
    UIImage *selectedImage = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childVc.tabBarItem.selectedImage = selectedImage;
    
    UINavigationController *nav;
    // 自定义导航栏控制器
    if ([childVc isKindOfClass:[HHYStockCalculateVC class]]||[childVc isKindOfClass:[FTQMineController class]]) {
        nav = [[HHYNaviVC alloc] initWithRootViewController:childVc];
        
    }else if ([childVc isKindOfClass:[GPIndexViewController class]]){
        nav = [[GPBaseNavigationController_NN alloc] initWithRootViewController:childVc];
    } else {
        nav = [[UINavigationController alloc] initWithRootViewController:childVc];
    }
    
    [self addChildViewController:nav];
    //设置选中及未选中字体颜色
    [nav.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:rgba(153, 153, 153, 1)} forState:UIControlStateNormal];
    [nav.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:rgba(255, 78, 19, 1)} forState:UIControlStateSelected];
}

@end
